/* 
 * Copyright 2011 kOSMik.
 * This file is part of kOSMik.
 * 
 * kOSMik is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * kOSMik is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with kOSMik.  If not, see <http://www.gnu.org/licenses/>.
 *  
 * kOSMik:
 * Open Street Map - Editor.
 * http://code.google.com/p/swp-dv-ws2010-osm-2/
 */

package de.fuberlin.kosmik.gui.dialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import de.fuberlin.kosmik.R;

/**
 * Collection of several dialogs.
 * 
 * @author Johannes
 */
public final class Dialogs {

	private Dialogs() {
		// Only static methods in this class
	}

	/**
	 * Use this dialog to display the user a message, which he is asked to
	 * press.
	 * 
	 * @param message The message which the user should take note of
	 * @param activity The context in which the message is to be placed
	 */
	public static void confirmMessage(String message, Activity activity) {
		AlertDialog.Builder builder = new AlertDialog.Builder(activity);
		builder.setMessage(message)
				.setCancelable(false)
				.setPositiveButton(activity.getString(R.string.dialog__btn_ok),
						new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int id) {
								dialog.cancel();
							}
						});
		// alertDialog.setIcon( R.drawable.ic_menu_add);
		AlertDialog alert = builder.create();
		alert.show();
	}

	/**
	 * Use this dialog to tell the user, that the requested functionality is not
	 * implemented yet.
	 * 
	 * @param activity The context in which the message is to be placed
	 */
	public static void notImplementedYet(Activity activity) {
		AlertDialog.Builder builder = new AlertDialog.Builder(activity);
		builder.setMessage(R.string.dialog__not_yet_implemented)
				.setCancelable(false)
				.setPositiveButton(activity.getString(R.string.dialog__btn_ok),
						new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int id) {
								dialog.cancel();
							}
						});
		// alertDialog.setIcon( R.drawable.ic_menu_add);
		AlertDialog alert = builder.create();
		alert.show();
	}

	/**
	 * Dialog to ask the user to confirm an action, or not.
	 * 
	 * @author Johannes
	 * @param activity the context the dialog is shown in
	 * @param message to call on user to enter some text
	 * @param onPositiveClickListener implement this listener to react of users
	 *            positive click action
	 */
	public static void confirmationDialog(Activity activity, final String message,
			OnClickListener onPositiveClickListener) {
		AlertDialog.Builder builder = new AlertDialog.Builder(activity);

		builder.setMessage(message)
				.setCancelable(true)
				.setPositiveButton(activity.getString(R.string.dialog__btn_ok),
						onPositiveClickListener)
				.setNegativeButton(activity.getString(R.string.dialog__btn_cancel), null);
		AlertDialog alert = builder.create();
		alert.show();
	}

	/**
	 * Dialog to motivate the user to enter some text. This dialog enables you
	 * to offers the user a list with suggestions he can make use of instead of
	 * typing a individual text
	 * 
	 * @author Johannes
	 * @param activity the context the dialog is shown in
	 * @param message to call on user to enter some text
	 * @param defaultEditText the text that is display in the edit field by
	 *            default
	 * @param autoCompleteItems the list of suggestions
	 * @param onClickListener implement this listener to react of users positive
	 *            click action
	 * @return an EditText view, that contains the text the user had choose
	 */
	public static EditText editDialog(Activity activity, String message,
			String defaultEditText, String[] autoCompleteItems,
			DialogInterface.OnClickListener onClickListener) {
		AlertDialog.Builder builder = new AlertDialog.Builder(activity);

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity,
				android.R.layout.simple_dropdown_item_1line, autoCompleteItems);
		AutoCompleteTextView editTrackNameView = new AutoCompleteTextView(activity);
		editTrackNameView.setAdapter(adapter);
		editTrackNameView.setText(defaultEditText);
		editTrackNameView.setSingleLine();
		// display dropdownbox after first typed character
		editTrackNameView.setThreshold(1);

		builder.setView(editTrackNameView)
				.setMessage(message)
				.setCancelable(true)
				.setPositiveButton(activity.getString(R.string.dialog__btn_ok), onClickListener)
				.setNegativeButton(activity.getString(R.string.dialog__btn_cancel), null);
		// alertDialog.setIcon( R.drawable.ic_menu_add);
		AlertDialog alert = builder.create();
		alert.show();
		return editTrackNameView;
	}

}
